
// non-generators must not be affected
test5to3(
'var a = function() {};',

'var a;\n\
a = function() {};'
);

// very basic generator
test5to3(
'var a = function() { yield 11; };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ ], function(b) {\n\
	if (b._continuation < 1) {\n\
		b._continuation = 1;\n\
		return 11;\n\
	} else if (b._continuation === 1) {\n\
		b._continuation = -1;\n\
		this._yieldReturn();\n\
	}\n\
});'
);

// multiple yields, but simple
test5to3(
'var a = function(b) { yield 11; yield a; yield b; };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ "b" ], function(c) {\n\
	if (c._continuation < 1) {\n\
		c._continuation = 1;\n\
		return 11;\n\
	} else if (c._continuation === 1) {\n\
		c._continuation = -1;\n\
		this._yieldReturn();\n\
	}\n\
	if (c._continuation < 2) {\n\
		c._continuation = 2;\n\
		return a;\n\
	} else if (c._continuation === 2) {\n\
		c._continuation = -1;\n\
		this._yieldReturn();\n\
	}\n\
	if (c._continuation < 3) {\n\
		c._continuation = 3;\n\
		return c._local_b;\n\
	} else if (c._continuation === 3) {\n\
		c._continuation = -1;\n\
		this._yieldReturn();\n\
	}\n\
});'
);

// yield inside a while loop
test5to3(
'var a = function(b) { while(true) yield b++; };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ "b" ], function(c) {\n\
	while (c._continuation === 1 || c._continuation < 1 && true)\n\
		if (c._continuation < 1) {\n\
			c._continuation = 1;\n\
			return c._local_b++;\n\
		} else if (c._continuation === 1) {\n\
			c._continuation = -1;\n\
			this._yieldReturn();\n\
		}\n\
});'
);

// yield inside a for loop
test5to3(
'var a = function(b) { var i; for(i = b; ;i++) yield i; };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ "b" ], function(c) {\n\
	for (c._continuation <= 0 && (c._local_i = c._local_b); c._continuation === 1 || c._continuation < 1 && true; c._local_i++)\n\
		if (c._continuation < 1) {\n\
			c._continuation = 1;\n\
			return c._local_i;\n\
		} else if (c._continuation === 1) {\n\
			c._continuation = -1;\n\
			this._yieldReturn();\n\
		}\n\
});'
);

// two yields inside a for loop
test5to3(
'var a = function(b) { var i; for(i = b; ;i++) { yield i; yield (i+2); } };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ "b" ], function(c) {\n\
	for (c._continuation <= 0 && (c._local_i = c._local_b); c._continuation === 2 || c._continuation === 1 || c._continuation < 1 && true; c._local_i++) {\n\
		if (c._continuation < 1) {\n\
			c._continuation = 1;\n\
			return c._local_i;\n\
		} else if (c._continuation === 1) {\n\
			c._continuation = -1;\n\
			this._yieldReturn();\n\
		}\n\
		if (c._continuation < 2) {\n\
			c._continuation = 2;\n\
			return c._local_i + 2;\n\
		} else if (c._continuation === 2) {\n\
			c._continuation = -1;\n\
			this._yieldReturn();\n\
		}\n\
	}\n\
});'
);

// yield inside a do-while
test5to3(
'var a = function(b) { var i = b; do { yield i++; } while (true); };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ "b" ], function(c) {\n\
	if (c._continuation < 1)\n\
		c._local_i = c._local_b;\n\
	do\n\
		if (c._continuation < 1) {\n\
			c._continuation = 1;\n\
			return c._local_i++;\n\
		} else if (c._continuation === 1) {\n\
			c._continuation = -1;\n\
			this._yieldReturn();\n\
		}\n\
	while (true);\n\
});'
);

// yields inside an "if" statement - one yield in each branch
test5to3(
'var a = function() { var i = 0; while (true) if (i % 2) { yield i; i += 11; } else { yield i; i += 21; } };',

'var a;\n\
a = Alkaline.Runtime.Generator.newInstance([ ], function(b) {\n\
	if (b._continuation < 1)\n\
		b._local_i = 0;\n\
	while (b._continuation === 2 || b._continuation === 1 || b._continuation < 1 && true)\n\
		if (b._continuation === 2 ? false : b._continuation === 1 ? true : b._local_i % 2) {\n\
			if (b._continuation < 1) {\n\
				b._continuation = 1;\n\
				return b._local_i;\n\
			} else if (b._continuation === 1) {\n\
				b._continuation = -1;\n\
				this._yieldReturn();\n\
			}\n\
			b._local_i += 11;\n\
		} else {\n\
			if (b._continuation < 2) {\n\
				b._continuation = 2;\n\
				return b._local_i;\n\
			} else if (b._continuation === 2) {\n\
				b._continuation = -1;\n\
				this._yieldReturn();\n\
			}\n\
			b._local_i += 21;\n\
		}\n\
});'
);

// named generator
test5to3(
'function n() { yield 0; }',

'var n;\n\
n = Alkaline.Runtime.Generator.newInstance([ ], function n(a) {\n\
	if (a._continuation < 1) {\n\
		a._continuation = 1;\n\
		return 0;\n\
	} else if (a._continuation === 1) {\n\
		a._continuation = -1;\n\
		this._yieldReturn();\n\
	}\n\
});'
);

/* TODO: FIXME: does not work yet:
var a = function () {
	var a = yield 0;
	while (true)
		a = yield a;
};
var b = a();
echo(b.next(1));
echo(b.next(2));
echo(b.next(3));
echo(b.next(4));
*/
